package models

import (
	"192.168.1.75/go-pkg/helper"
	"gorm.io/gorm"
)

// LocationPoints 商场积分对接
type LocationPoints struct {
	ID              string  `json:"id" gorm:"column:id;primaryKey;type:int;size:64;comment:主键"`
	LocationID      string  `json:"location_id" gorm:"column:location_id;type:string;size:40;index:location_id,unique;comment:位置ID"`
	PointsID        string  `json:"points_id" gorm:"column:points_id;type:int;size:64;comment:积分id"`
	MallID          string  `json:"mall_id" gorm:"column:mall_id;type:varchar(50);not null;default:'';comment:商场id"`
	Sort            int64   `json:"sort" gorm:"column:sort;type:int;size:64;default:0;comment:排序,默认0,最大999"`
	BackgroundImage string  `json:"background_image" gorm:"column:background_image;type:string;size:200;comment:支付背景图"`
	PointsValue     float64 `json:"points_value" gorm:"column:points_value;type:float;size:64;default:0;comment:积分价值"`
	CreatedAt       int64   `json:"created_at" gorm:"autoCreateTime;column:created_at;type:int;size:64;comment:创建时间"`
	UpdatedAt       int64   `json:"updated_at" gorm:"autoUpdateTime;column:updated_at;type:int;size:64;comment:更新时间"`
}

// TableName 表名
func (LocationPoints) TableName() string {
	return "location_points"
}

// BeforeCreate 自增id
func (l *LocationPoints) BeforeCreate(tx *gorm.DB) (err error) {
	if l.ID != "" {
		return nil
	}
	// id为空时，自动添加id
	uuid, err := helper.UUID{}.String()
	if err != nil {
		return err
	}
	l.ID = uuid
	return nil
}

// 模式自动注册
func init() {
	Models = append(Models, &LocationPoints{})
}
